<?php 
/**
 * 主页设置视图
 */
	class HomeAction extends CommonAction{
		public function index(){
			//获取背景图
			$filesname=scandir("./Public/images/bg/");
			$this->bgs=getImgId($filesname);
			//获取热门标签
			$this->hot=C('hot');
			//获取首页图
			$filesname=scandir("./Public/images/art/");
			$this->arts=getImgId($filesname);
			$this->display();
		}
		/**
		 * 表单处理
		 */
		public function Handle(){
			$_POST['hot']=array_filter($_POST["hot"]);
		 	if(F('home',$_POST,'./APP/Conf/')){
		 		$this->success('设置成功!');
			}else $this->error('设置失败');
		}

		/**
		 * 背景图管理视图
		 */
		public function bgimg(){
			$filesname=scandir("./Public/images/bg/");
			$this->imgs=getImgId($filesname);
			$this->name=背景图;
			$this->path="bg";
			echo $this->id=(int)end($this->imgs)+1;
			$this->display('img');
		}

		/**
		 * 首页图管理视图
		 */
		public function artimg(){
			$filesname=scandir("./Public/images/art/");
			$this->imgs=getImgId($filesname);
			$this->name=首页图;
			$this->path="art";
			echo $this->id=(int)end($this->imgs)+1;
			$this->display('img');
		}

		public function delimg(){
			if(unlink("./Public/images/".$_GET['path']."/".$_POST['img'].".jpg"))
				$this->success('删除成功!');
			else $this->error("删除失败!");
		}

		public function upimg(){
			import('ORG.Net.UploadFile');
			$upfile=new UploadFile;
			// $img['savepath']="./Public/images/".$_GET['path']."/";
			// $img['savename']=
			// $img["tmp_name"]=$_FILES['img']["tmp_name"];
			// dump($img);
			echo $_FILES["img"]["name"]=$_GET['name'].".jpg";
			if($upfile->uploadOne($_FILES["img"],"./Public/images/".$_GET['path']."/"))
				$this->success("上传成功!");
			else $this->error($upfile->getErrorMsg());
		}
	}

	function getImgId($filesname){
		$result=array();
			foreach ($filesname as $k => $v) {
				if($k>1)
				$result[]=preg_replace('/.jpg/','', $v);
			}
		return $result;
	}